﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Net;
using System.Web.Services;
using GoogleEarthClasses.Data;
using GoogleEarthClasses.Global;
using GoogleEarthClasses.Logic;
using GoogleEarthClasses.Entities;
namespace WebService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://www.dev-poleposition.com/Deploy/WebService/",
                Description = "POLE POSITION WEBSERVICE.")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]

    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public byte[] GetThumbails(int IdPosition, int ImageId, int Width)
        {
            byte[] _Image = DImage.GetImage(ImageId);
            _Image = GImages.ResizeImageFile(_Image, Width);
            return _Image;           
        }
        [WebMethod]
        public string GetLastVersion()
        {
            try
            {
                return DConfig.GetLastVersion();
            }
            catch (Exception)
            {
                throw;
            }             
        }
        [WebMethod]
        public List<string> GetColors()
        {
            try
            {
                List<string> m_Colors = new List<string>();
                DataTable dt = DColor.SelectAll();
                foreach (DataRow dr in dt.Rows)
                {
                    m_Colors.Add(dr["Color"].ToString());
                }
                return m_Colors;

            }
            catch (Exception)
            {
                throw;
            }
        }

        #region POLYGONS
        [WebMethod]
        public Int32 PolygonInsert(string CreatedBy, string CreatedAt, string UpdatedBy, string UpdatedAt, string UpdatedReason, string Name, string TypeName, string Points, string Description)
        {
            try
            {
                return DPolygon.Insert(CreatedBy, CreatedAt, UpdatedBy, UpdatedAt, UpdatedReason, Name, TypeName, Points, Description);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [WebMethod]
        public void PolygonUpdate(Int32 PolygonId, string UpdatedBy, string UpdatedAt, string UpdatedReason, string Name, string TypeName, string Points, string Description)
        {
            try
            {
                DPolygon.Update(PolygonId, UpdatedBy, UpdatedAt, UpdatedReason, Name, TypeName, Points, Description);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [WebMethod]
        public void PolygonDelete(int PolygonId)
        {
            try
            {
                DPolygon.Delete(PolygonId);
            }
            catch (Exception)
            {
                throw;
            }
        }        
        #endregion POLYGONS

        #region POSITIONS
        [WebMethod]
        public int PositionInsert(double Longitude, double Latitude, double Altitude, string Description, DateTime SatelliteTime, int Satellites, double angle, string Color)
        {
            return DPoint.Insert(Longitude, Latitude, Altitude, Description, SatelliteTime, Satellites, angle, Color);
        }
        [WebMethod]
        public void PositionUpdate(int PositionId, double Longitude, double Latitude, double Altitude, string Description, DateTime SatelliteTime, int Satellites, double angle, string Color)
        {
            try
            {
                DPoint.Update(PositionId, Longitude, Latitude, Altitude, Description, SatelliteTime, Satellites, angle, Color);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [WebMethod]
        public void PositionDelete(int PositionId)
        {
            try
            {
                DPoint.Delete(PositionId);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// DELETES ALL THE IMAGES FOR A SPECIFIC POINT.
        /// USED WHEN NEED TO RESTART IMAGE UPLOADING
        /// </summary>
        [WebMethod]
        public void PositionImageDeleteAll(int PositionId)
        {
            try
            {
                LImage.DeleteIncompleted(PositionId);
            }
            catch (Exception)
            {
                throw;
            }
        }

        
        [WebMethod]
        public int PositionImageInsert(int IdInsertedPosition, string Name, byte[] ImageBytes)
        {
            return DPoint.InsertPositionImages(IdInsertedPosition, Name, ImageBytes);
        }

        [WebMethod]
        public void PositionImageDelete(int IdImage)
        {
            DPoint.DeletePositionImage(IdImage);
        }
        [WebMethod]
        public void SetParent(int PositiondId, int ParentPositionId)
        {
            try
            {
                DPoint.SetParent(PositiondId, ParentPositionId);
            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion POSITIONS
    }
}
